home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8966 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q: how to store class member function pointers in class B
  5. Date: 27 Feb 1996 17:18:54 GMT
  6. Organization: self-employed
  7. Message-ID: <4gvedu$cj8@news.bridge.net>
  8. References: <4gvdei$rra@news.Silvaco.COM>
  9. NNTP-Posting-Host: ppp-mia2-71.bridge.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15.  
  16. >>>>>>>>
  17. class Button : public ProtoButton {
  18.   void (Panel::*function)(void);
  19.  
  20.   void inheritedCallback(void) {
  21.     this->*function();                  woops!
  22.   }
  23.  
  24.   Button((Panel::*func)(void)) {
  25.     function = func;
  26.   }
  27. }
  28. <<<<<<<<<
  29.  
  30.  
  31.   Mike;
  32.  
  33.   Imagine that the "this" pointer is passed as an 'invisible' parameter 
  34. to all nonstatic member functions (which is the case in most compilers). 
  35. Its type is checked, otherwise you would be able to use members of one 
  36. class on another class - which is what your code tries to do.
  37.  
  38.   You are trying to call a member function of class Panel, but the base 
  39. address that you are specifying is the address of a Button.
  40.  
  41.   You will need to store the address of a Panel object as well.
  42.  
  43.                              David
  44.  
  45.  
  46.